//
//  BaseNavigationController.m
//  Cycling
//
//  Created by cjg.mini on 2023/3/3.
//

#import "BaseNavigationController.h"

@interface BaseNavigationController ()

@end

@implementation BaseNavigationController

+ (void)initialize{
    //设置导航栏背景
    NSArray *array = [NSArray arrayWithObjects:[self class], nil];
    UINavigationBar *bar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses: array];
    [bar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:(UIBarMetricsDefault)];
    bar.backgroundColor = COLOR_WHITE;
    [bar setTranslucent:NO];

    UIView *statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, -SafeAreaTopHeight, SCREEN_W, SafeAreaTopHeight)];
    statusBarView.backgroundColor=COLOR_WHITE;
    [bar addSubview:statusBarView];
    [bar setTitleTextAttributes:@{NSFontAttributeName:FONT_PRIMARY_TITLE,NSForegroundColorAttributeName:COLOR_BLACK}];

}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.interactivePopGestureRecognizer.delegate = (id)self;

}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.childViewControllers.count > 0) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateHighlighted];
        
        btn.ce_size = CGSizeMake(70, 44);
        [btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    }
    [super pushViewController:viewController animated:animated];
}
- (void)back{
    [self popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(BOOL)shouldAutorotate
{
    return YES;
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return [self.viewControllers.lastObject supportedInterfaceOrientations];
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];
}

@end
